<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta property="og:type" content="website">
<meta property="og:title" content="RemarkableRide">
<meta property="og:url" content="https://github.com/remarkableRide/io/index.html">
<meta property="og:site_name" content="RemarkableRide">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="RemarkableRide">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://github.com/remarkableRide/io/"/>





  <title> RemarkableRide </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">RemarkableRide</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocapitalize="off" autocomplete="off" autocorrect="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://github.com/remarkableRide/io/2017/05/23/当我们在调用this的时候，调用的到底是什么？/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="remarkableRide">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RemarkableRide">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2017/05/23/当我们在调用this的时候，调用的到底是什么？/" itemprop="url">
                  当我们在调用this的时候，调用的到底是什么？
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-23T09:50:20+08:00">
                2017-05-23
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,341
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  5
                </span>
              
            </div>
          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="What-is-this"><a href="#What-is-this" class="headerlink" title="What is this ?"></a>What is this ?</h2><p>this到底是什么，之前我在写到执行上下文环境时，说到<code>this</code>也是其中的一个对象，还有<code>arguments</code>,<a href="https://remarkableride.github.io/2017/05/18/JS作用域/" target="_blank" rel="external">点我传送</a>,<code>this</code>是JS语言当中的关键字，在<code>C# , java</code>中也有此关键字，使用的方法也类似。这里先抛出一个结论：<code>this</code>的使用，是为了更优雅的传递对一个对象的引用。可以极大的简化代码的结构，当然，如果用不好就会很懵逼了。例一：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">a</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	<span class="keyword">return</span> <span class="keyword">this</span>.name;</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> me = &#123;</div><div class="line">	<span class="attr">name</span>:<span class="string">"帅的一塌糊涂"</span></div><div class="line">&#125;;</div><div class="line">a.call(me);    <span class="comment">//  "结果你懂的"</span></div></pre></td></tr></table></figure></p>
<p>而不使用<code>this</code>时，我们的函数就需要显式的用一个参数来传递对对象的引用：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">a</span>(<span class="params">context</span>)</span>&#123;</div><div class="line">	<span class="keyword">return</span> context.name;</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> me = &#123;</div><div class="line">	<span class="attr">name</span>:<span class="string">"帅的一塌糊涂"</span></div><div class="line">&#125;;</div><div class="line">a(me);</div></pre></td></tr></table></figure></p>
<p>不使用<code>this</code>冒似看上去比使用更容易理解，但实际生产中代码远远没有这么简单，要是一直使用显式参数传递上下文对象会让代码变得混乱。所以，我们应该去深入<code>this</code>的用法，网上的关于<code>this</code>的用法，一般分为4类，1，直接调用；2，作为对象的方法调用；3，作为构造函数调用；4，显式绑定call，apply调用。我认为这四种实际可分为两种情况。</p>
<h4 id="Rule-No-1-this-总是指向最后调用它的那个对象："><a href="#Rule-No-1-this-总是指向最后调用它的那个对象：" class="headerlink" title="Rule.No.1: this 总是指向最后调用它的那个对象："></a><strong>Rule.No.1: <code>this</code> 总是指向最后调用它的那个对象</strong>：</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> b = <span class="number">1</span>,</div><div class="line">    c =&#123;</div><div class="line">       <span class="attr">b</span>:<span class="number">2</span></div><div class="line">&#125;;</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">a</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	<span class="built_in">console</span>.log(<span class="keyword">this</span>.b)</div><div class="line">&#125;</div><div class="line">a();    <span class="comment">//  1</span></div><div class="line"><span class="built_in">window</span>.a === a;    <span class="comment">//  true</span></div><div class="line">c.a = a;</div><div class="line">c.a();    <span class="comment">//  2</span></div><div class="line"><span class="built_in">window</span>.c.a === c.a;    <span class="comment">//  true</span></div></pre></td></tr></table></figure>
<p>这个例子中，我加入了<code>window</code>对象便于理解，实际上我们定义在全局中的函数也是这样被调用，我们书写的时候可以省略掉<code>window</code>，像一种小的语法糖。先说这个例子的意外情况，在声明严格模式下，不允许<code>this</code>默认绑定到最外层的<code>window</code>对象上，也就是严格模式会输出<code>undefined</code>。而<code>window.c.a()</code>之所以会输出2，就是我们说的作为对象的方法调用，对应了规则一：<code>this</code>总是指向最后调用它的那个对象。即便c对象处于一个非全局作用域中(其他函数作用域)调用也是这个结果。</p>
<h4 id="Rule-No-2-使用call-apply调用函数时传递的第一个参数即为this的值，俗称‘硬绑定’："><a href="#Rule-No-2-使用call-apply调用函数时传递的第一个参数即为this的值，俗称‘硬绑定’：" class="headerlink" title="Rule.No.2: 使用call,apply调用函数时传递的第一个参数即为this的值，俗称‘硬绑定’："></a><strong>Rule.No.2: 使用<code>call,apply</code>调用函数时传递的第一个参数即为<code>this</code>的值，俗称‘硬绑定’：</strong></h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = <span class="number">1</span>,</div><div class="line">    b =&#123;</div><div class="line">       <span class="attr">a</span>:<span class="number">2</span>,</div><div class="line">    &#125;,</div><div class="line">    c = &#123;&#125;;</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">foo</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	<span class="built_in">console</span>.log(<span class="keyword">this</span>.a);</div><div class="line">&#125;</div><div class="line">foo.call(b);    <span class="comment">//  2</span></div><div class="line">foo.call(a);    <span class="comment">//  undefined</span></div><div class="line">foo.call(c);    <span class="comment">//  undefined</span></div><div class="line">foo.call(<span class="keyword">this</span>);    <span class="comment">//  1</span></div><div class="line">foo.call();    <span class="comment">//  1</span></div></pre></td></tr></table></figure>
<p>调用<code>call</code>方法时，或者写入<code>this</code>为绑定到默认对象，此例中的默认对象为<code>window</code>。当作为构造函数调用时，指向构造函数也是<code>call</code>方法的变换，而<code>new</code>实例也是该方法的变种：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">foo</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	<span class="keyword">this</span>.c=<span class="number">1</span>;</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> foo();    <span class="comment">//  实际等价于下面代码</span></div><div class="line"><span class="keyword">var</span> b = &#123;&#125;;</div><div class="line">b.__proto__ = foo.prototype;</div><div class="line"><span class="keyword">var</span> result=foo.call(b);</div><div class="line"><span class="keyword">return</span> <span class="keyword">typeof</span> result ===<span class="string">'obj'</span> ? result : b;</div></pre></td></tr></table></figure></p>
<p>使用<code>new</code>关键字构造对象，等价于新建一个对象，把对象的原型绑定在函数的原型上，再到对象的作用域中调用函数，实际即把函数的<code>this</code>绑定到对象上，最后一步，检测返回值，网上好多关于<code>new</code>的定义都没写这一步，如果该函数有返回值，那么新建对象则应包含函数的返回值，否则就为对象本身。<em>可以看出，作为构造函数调用时，<code>this</code>的指向为<code>new</code>出来的对象，都是<code>call</code>方法的功劳。对应了规则2</em>。<br>再来看一个例子：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = &#123;</div><div class="line">	<span class="attr">b</span> : <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; <span class="built_in">console</span>.log(<span class="keyword">this</span>.c) &#125; &#125;,</div><div class="line">	<span class="attr">c</span>:<span class="number">3</span></div><div class="line">&#125;;</div><div class="line"><span class="keyword">var</span> c = <span class="number">5</span>;</div><div class="line"><span class="keyword">var</span> d = &#123; <span class="attr">c</span>:<span class="number">10</span> &#125;;</div><div class="line">a.b()();    <span class="comment">//  5</span></div><div class="line">a.b().call(a);    <span class="comment">//  3</span></div><div class="line">a.b().call(d);    <span class="comment">//  10</span></div></pre></td></tr></table></figure></p>
<p>有些教程认为，<code>a.b()()</code>调用时<code>this</code>绑定到最外层的<code>window</code>是规则之外，个人不敢苟同，此例中<code>a.b()</code>返回的是一个完整的函数，函数在全局作用域调用，自然<code>this</code>就绑定到了最外层，同理，用<code>call</code>方法改变作用域后，<code>this</code>也绑定到了<code>call</code>方法的第一个参数对象中。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">foo</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	<span class="built_in">console</span>.log(<span class="keyword">this</span>.c);</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> a = &#123;</div><div class="line">	<span class="attr">c</span>:<span class="number">3</span>,</div><div class="line">	<span class="attr">foo</span>:foo</div><div class="line">&#125;;</div><div class="line"><span class="keyword">var</span> bar = a.foo;</div><div class="line"><span class="keyword">var</span> c = <span class="number">10</span>;</div><div class="line">bar();    <span class="comment">//  10</span></div><div class="line">a.foo();    <span class="comment">//  3</span></div></pre></td></tr></table></figure></p>
<p>这段代码来源于《你不知道的JavaScript》，书中将<code>bar()</code>输出为10定义为隐式丢失。这样其实比较难以理解，这里实际考察的是<code>=</code>函数赋值行为到底是在干什么，函数赋值给变量，变量中储存的实际上是指向<strong>函数本身</strong>内存的指针，与函数名无关。可以想象成匿名函数，函数名仅仅是一个标签，可随时更换。也就解释了<code>foo</code>函数依据调用环境的不同而输出不同的数字。</p>
<h3 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h3><p>闭包，原型链，<code>this</code>可以说是JS语言中的三座大山，也是这门语言的基石。无论怎么深入都不过分，尤其是在现在前端框架层出不穷的时候，<code>angular</code>,<code>vue</code>,<code>react</code>和各种JS库，能基础运用这些框架很简单，而想了解框架背后所蕴含的思想却大不简单。而不能了解一门语言的精髓，不了解一个框架的内部构造，始终都会被新出的框架牵着鼻子走，唯有深入JS内部，知晓它的长处，不足。才能在这些新新技术中做出合适的选择。</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://github.com/remarkableRide/io/2017/05/18/JS作用域/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="remarkableRide">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RemarkableRide">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2017/05/18/JS作用域/" itemprop="url">
                  JS作用域
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-18T19:40:21+08:00">
                2017-05-18
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,084
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  4
                </span>
              
            </div>
          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="JS引擎的工作流程"><a href="#JS引擎的工作流程" class="headerlink" title="JS引擎的工作流程"></a>JS引擎的工作流程</h2><p>上一章说到函数声明会自动提前，实际就是JS引擎的功劳，电脑CPU只能理解二进制代码，而我们书写的程序需要经过编译之后形成机器码才能输入给CPU执行，这段过程称为编译：包括词法分析-把代码分割成最小化，语法分析-重新组合代码，语义分析-生成语法树，然后是中间代码生成，再经过链接器的链接生成最后的可执行机器码。JS的作为一门解释性语言的差别体现在边编译边执行。而执行编译的便是JS引擎，比如比较著名的谷歌chrome浏览器v8引擎。</p>
<h3 id="作用域的确定"><a href="#作用域的确定" class="headerlink" title="作用域的确定"></a>作用域的确定</h3><p><strong>JS语言的作用域指的是函数和变量的可访问的范围</strong>，JS中没有块级作用域，比如<code>if(){}</code>,<code>for(){}</code>这些语句块内部定义的变量外部都是能拿到的，这里不举例，与这句话相对应的是JS中只存在函数作用域和全局作用域。而作用域的创建是在函数定义的时刻，与函数是否被调用无关：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> c = <span class="number">1</span>;</div><div class="line"><span class="keyword">var</span> a = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123; </div><div class="line">        <span class="built_in">console</span>.log(c);</div><div class="line">&#125;;</div><div class="line"><span class="keyword">var</span> b = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	<span class="keyword">var</span> c = <span class="number">2</span>;</div><div class="line">        a();    </div><div class="line">&#125;;</div><div class="line">b();    <span class="comment">//  此时会打印1，而不是2</span></div></pre></td></tr></table></figure></p>
<p>我在刚开始遇到这个问题时，百思不得其解，为什么函数会拿到外部的c，而对里面的c无动于衷，不是说好的，变量的查找是沿着作用域链一级一级往上查找，最近的最先找到么？想要弄明白这个问题，就要知道JS解析这段代码时发生了什么。JS解析一个函数的调用时，实际会载入被调用函数的执行上下文环境，这个熟悉的名字，我们常说的<code>this</code>，也是执行上下文环境的一部分，下面让我们来模仿一下JS引擎的思维方式，来解析一下这段代码。走起：<br>第一步，我们在全局下提取变量声明和函数声明:<table class="table table-bordered table-striped table-condensed"><tr><td>全局上下文环境-代码开始开始解析</td><td></td></tr><tr><td>c</td><td>undefined</td></tr><tr><td>a</td><td>undefined</td></tr><tr><td>b</td><td>undefined</td></tr></table><table class="table table-bordered table-striped table-condensed"><tr><td>全局上下文环境-代码解析到第8行</td><td>进行赋值</td></tr><tr><td>c</td><td>1</td></tr><tr><td>a</td><td>function</td></tr><tr><td>b</td><td>function</td></tr></table>在执行到第9行时，调用b函数，同时，会创建一个b函数的新的执行上下文环境：<table class="table table-bordered table-striped table-condensed"><tr><td>b函数的上下文环境</td><td></td></tr><tr><td>局部变量c</td><td>2</td></tr><tr><td>this</td><td>window</td></tr><tr><td>arguments</td><td>undefined</td></tr></table>然后，引擎进入b函数内部，也就是第五行，b函数的上下文环境会被载入到上下文环境栈，一个压栈的操作：<table class="table table-bordered table-striped table-condensed"><tr><td>b函数的上下文环境-栈顶</td></tr><tr><td>全局上下文环境-栈底</td></tr></table>继续解析到第7行，调用a函数，与刚才一样，创建一个a函数的上下文环境并执行压栈，但是，此时a的执行上下文中并没变量c的定义，这个时候，引擎会到<em>创建a函数的作用域中去取值</em>，也就是我们所说的跨域，而此时的a函数定义在全局作用域中，自然也就拿到了<code>c=1</code>的值并输出。那什么情况下a函数会输出<code>c=2</code>呢，只有当a函数身处b函数的作用域中时，也就是，a函数在b的作用域中定义。这也很好的解释了闭包的原理：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">f1</span>(<span class="params"></span>)</span>&#123;</div><div class="line">　　<span class="keyword">var</span> n=<span class="number">999</span>;</div><div class="line">　　<span class="function"><span class="keyword">function</span> <span class="title">f2</span>(<span class="params"></span>)</span>&#123;</div><div class="line">　　　　　　alert(n); </div><div class="line">　　&#125;</div><div class="line">　　<span class="keyword">return</span> f2;</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> result=f1();</div><div class="line">result();     <span class="comment">//  999</span></div></pre></td></tr></table></figure></p>
<p>此例来源于:<a href="http://www.ruanyifeng.com/blog/2009/08/learning_javascript_closures.html" target="_blank" rel="external">阮一峰的网络日志</a>;<br>按照我们刚才分析的思路，来解释一下这个例子就很容易了，首先f1返回的是一个函数，当调用这个函数的时候，JS引擎就会先进入到f2函数作用域中寻找n的值，结果当然是没有，接下来跨域到<strong>创建f2函数的f1函数作用域</strong>中寻找，找到了<code>n=999</code>并输出：<table class="table table-bordered table-striped table-condensed"><tr><td>f2函数的上下文环境-栈顶</td></tr><tr></tr><tr><td>f1函数的上下文环境</td></tr><td>全局上下文环境-栈底</td></table><br>而此时由于f2函数引用了f1函数中的变量，导致f1函数的上下文环境并不能从内存中释放，直到第9行f2函数调用结束。这也是我们常说的闭包的弊端：增加内存开销。</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://github.com/remarkableRide/io/2017/05/10/探索JS原型链/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="remarkableRide">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RemarkableRide">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2017/05/10/探索JS原型链/" itemprop="url">
                  探索JS原型链
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-10T22:26:22+08:00">
                2017-05-10
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  1,479
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  6
                </span>
              
            </div>
          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="踏入面向对象的世界"><a href="#踏入面向对象的世界" class="headerlink" title="踏入面向对象的世界"></a>踏入面向对象的世界</h2><p>最近在观看Zepto源码解析的视频时，老师又讲到了$对象与普通对象的区别，还记得《锋利的jquery》一书中说，$对象与普通对象的区别在于，$对象是一个数组结构的对象，但没有数组的push，shift方法。想必在控制台大家也注意这对”[]”。那么它内部是如何实现这个不是数组的对象呢？其实实现这个方法非常容易，也就是这个方法，体现了JS作为一门面向对象编程语言的继承功能——JS原型链。</p>
<h3 id="JS原型英文解析"><a href="#JS原型英文解析" class="headerlink" title="JS原型英文解析"></a>JS原型英文解析</h3><p>Every JavaScript object has a prototype. The prototype is also an object.<br>All JavaScript objects inherit their properties and methods from their prototype.</p>
<p><strong>JavaScript Prototypes</strong><br>All JavaScript objects inherit the properties and methods from their prototype.<br>Objects created using an object literal, or with new Object(), inherit from a prototype called Object.prototype.<br>Objects created with new Date() inherit the Date.prototype.<br>The Object.prototype is on the top of the prototype chain.<br>All JavaScript objects (Date, Array, RegExp, Function, ….) inherit from the Object.prototype.<br>More info: <a href="http://w3schools.bootcss.com/js/js_object_prototypes.html" target="_blank" rel="external">w3schools</a><br>首先说下为什么要拉出英文的定义，我在写这篇文档时，查看了前3页的搜索“JS原型链”的文章，其中定义最清晰简洁的还要属w3school，一般来说访问这个网站需要翻墙，国内有一个汉化版，但是不全，比较新的内容没有搬过来，比如英文版的w3school有一个w3.css的小框架，用法跟bootstrap一样，都是往class标签里添加类，用起来比bootstrap更小巧。不过比较冷门。<br>引用的英文的意思是说，每个JS对象都有一个原型，原型也是对象，JS对象从原型那里继承了属性和方法。既然每个对象都有原型，那肯定有一个顶，也就是原型链最深处的原始原型，下文也说了，即<strong>Object.prototype</strong>，但，这里有一个常见的误区，就是把原型和对象的prototype属性划等号。在ECMAScript5的语法当中，prototype是函数特有的属性，实例对象的原型则是<code>__proto__</code>,<code>prototype</code>用来存放函数继承给下一代的东西，但是直接访问是访问不到的。例一：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;&#125;;</div><div class="line">a.prototype.b=<span class="number">3</span>;</div><div class="line">a.b;   <span class="comment">//  undefined</span></div><div class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> a();</div><div class="line">b.b;   <span class="comment">//  3</span></div></pre></td></tr></table></figure>
<p>这里用new关键字构造了b对象，此时a也称为构造函数，构造函数很容易和<code>constructor</code>属性弄混，尤其是：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> a () ;</div><div class="line">b.constructor === a;   <span class="comment">//  true</span></div></pre></td></tr></table></figure></p>
<p>这里返回的true让人觉得这是b由a构造的证据，but，实际上不是，<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">b.hasOwnProperty(<span class="string">"constructor"</span>);   <span class="comment">//  false</span></div></pre></td></tr></table></figure></p>
<p>b中并没有<code>constructor</code>属性，那这个属性是哪里来的呢，根据原型继承，JS会沿着原型链向上查找，首先是<code>a.prototype</code>:<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">b.__proto__ === a.prototype;   <span class="comment">//  true</span></div><div class="line">a.prototype.hasOwnProperty(<span class="string">"constructor"</span>);   <span class="comment">//  true</span></div><div class="line">b.constructor === a.prototype.constructor;   <span class="comment">//  true</span></div></pre></td></tr></table></figure></p>
<p>实际上<code>b.constructor</code>是a原型链上的属性，而a的原型链之所以有这个属性，也正是指出了a的原型链是a对象在实例化出来的同时由a对象构造出来存放继承属性及方法的地方。不过由于<code>constructor</code>属性可以随意更改，所以单凭该属性来判定函数原型的构造很危险，也并不常用。a函数对象的实例化：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;&#125;;</div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">a</span>(<span class="params"></span>) </span>&#123;&#125;;</div><div class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="built_in">Function</span> () ;</div></pre></td></tr></table></figure></p>
<p>以上3种方法是等价的，唯一不同的是<code>function a () {}</code>函数声明会前置，这里涉及到JS引擎解析代码的过程，略过不提。<br>第3种方法也揭示了创建一个函数也是一个实例化，常用的<code>Array，String，Boolean</code>。实际上也是<code>Function</code>函数的实例化对象。<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">Array</span>.__proto__ === <span class="built_in">Function</span>.prototype;   <span class="comment">//true</span></div><div class="line"><span class="built_in">Boolean</span>.__proto__ === <span class="built_in">Function</span>.prototype;   <span class="comment">//true</span></div></pre></td></tr></table></figure></p>
<p>常用的数组方法，push，pop，shift，也是定义在Array的Prototype上：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">console</span>.log(<span class="built_in">Array</span>.prototype);</div></pre></td></tr></table></figure></p>
<p>回到刚开始的问题：$()对象是类数组的结构，却没有数组的方法，即$()实际的原型不是指向Array函数的prototype。例：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = <span class="keyword">new</span> <span class="built_in">Array</span>();</div><div class="line">a.push(<span class="number">1</span>);   <span class="comment">//  1</span></div><div class="line">a.__proto__ = <span class="keyword">new</span> <span class="built_in">Object</span>();</div><div class="line">a.push(<span class="number">2</span>);   <span class="comment">//  Uncaught TypeError</span></div></pre></td></tr></table></figure></p>
<p>更改了a数组的原型指向，便没有了数组上定义的方法。</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>函数的<code>prototype</code>对象存放着该函数实例化对象继承的方法，<code>Array</code>等函数的定义更像是实现了一个方法集。一个面向对象编程语言当中类的概念。但并不完美，譬如函数本身无法访问到，所以便有了JS当中的特权方法，也就是另一个难点<code>this</code>的指向，下一章，我将会对JS的作用域进行分析，想要理解<code>this</code>的指向问题，闭包，实际上就是理解函数在执行时的作用域的变化。<br><code>prototype</code>对象中若是定义了一个引用类型的方法或者是属性，当其中的一个实例进行了修改操作，其原型链上的所有实例都会收到影响，所以，引用类型的方法或者属性应该避免定义在原型上，可以改用this：<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</div><div class="line">	a.prototype.array=[<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>];</div><div class="line">&#125;</div><div class="line"><span class="keyword">var</span> b = <span class="keyword">new</span> a();</div><div class="line"><span class="keyword">var</span> c = <span class="keyword">new</span> a();</div><div class="line">b.array.push(<span class="number">4</span>);   <span class="comment">//  [1,2,3,4]</span></div><div class="line"><span class="built_in">console</span>.log(c);   <span class="comment">//  [1,2,3,4]</span></div></pre></td></tr></table></figure></p>
<h3 id="题外话"><a href="#题外话" class="headerlink" title="题外话"></a>题外话</h3><p>这篇文章从10号晚上开始写，今天14号。比预计的进度慢，期间严重感冒，一度坐在电脑面前咳咳咳，除了上班剩下的时间都用来睡觉恢复了。今天感冒消散，赶紧把挖的洞补上。想说的是，写博客确实是一个人能力提升的好办法，从写的时候上网查资料，到转化为自己理解的语言，再进行代码测试，最后发布。这种用输出倒逼输入的过程比自己看书，看视频学习的效率要高上不少，难怪有老的程序员说，想要提高，就要自己写博客。也希望自己能够越写越顺畅~</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://github.com/remarkableRide/io/2017/05/03/博客添加功能/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="remarkableRide">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RemarkableRide">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2017/05/03/博客添加功能/" itemprop="url">
                  博客添加功能
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-03T23:46:04+08:00">
                2017-05-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  191
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  1
                </span>
              
            </div>
          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p><img src="https://timgsa.baidu.com/timg?image&amp;quality=80&amp;size=b9999_10000&amp;sec=1493223838128&amp;di=c9a4b5d92b7ab41789dbde3069dbaf3a&amp;imgtype=0&amp;src=http%3A%2F%2Fpic4.zhimg.com%2Fd4c1239e75c02e8482c22017a6c8d407_r.jpg" alt="当你看到这行文字的时候，代表图片挂了"></p>
<h1 id="升级版本"><a href="#升级版本" class="headerlink" title="升级版本"></a>升级版本</h1><p>之前的博客用的是Hexo默认的主题，今天根据网上的攻略换成了next主题，<a href="http://theme-next.iissnan.com/" target="_blank" rel="external">next主题的官方文档</a>，依次添加了评论模块，搜索，标签，其中音乐模块的添加来自<a href="http://cherryblog.site/" target="_blank" rel="external">如何在Hexo中添加网易云音乐</a>。</p>
<h3 id="遗留的问题，Hexo发布文章时，需要先在命令行中输入hexo-g-否则页面调试时加载不出对应的文章。"><a href="#遗留的问题，Hexo发布文章时，需要先在命令行中输入hexo-g-否则页面调试时加载不出对应的文章。" class="headerlink" title="遗留的问题，Hexo发布文章时，需要先在命令行中输入hexo g,否则页面调试时加载不出对应的文章。"></a>遗留的问题，Hexo发布文章时，需要先在命令行中输入hexo g,否则页面调试时加载不出对应的文章。</h3><h3 id="来必应的加载速度很慢，会出现评论无法显示的情况，体验不佳。"><a href="#来必应的加载速度很慢，会出现评论无法显示的情况，体验不佳。" class="headerlink" title="来必应的加载速度很慢，会出现评论无法显示的情况，体验不佳。"></a>来必应的加载速度很慢，会出现评论无法显示的情况，体验不佳。</h3><h2 id="改善建议："><a href="#改善建议：" class="headerlink" title="改善建议："></a>改善建议：</h2><h4 id="1，利用码云云加速，提高网站的访问速度。"><a href="#1，利用码云云加速，提高网站的访问速度。" class="headerlink" title="1，利用码云云加速，提高网站的访问速度。"></a>1，利用码云云加速，提高网站的访问速度。</h4><h4 id="2，若1无显著效果，考虑将内容部署到自己的服务器上，提升稳定性。"><a href="#2，若1无显著效果，考虑将内容部署到自己的服务器上，提升稳定性。" class="headerlink" title="2，若1无显著效果，考虑将内容部署到自己的服务器上，提升稳定性。"></a>2，若1无显著效果，考虑将内容部署到自己的服务器上，提升稳定性。</h4>
          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://github.com/remarkableRide/io/2017/05/01/hello/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="remarkableRide">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RemarkableRide">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2017/05/01/hello/" itemprop="url">
                  Hello
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-01T18:39:23+08:00">
                2017-05-01
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  217
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  1
                </span>
              
            </div>
          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="Hexo的建站之旅"><a href="#Hexo的建站之旅" class="headerlink" title="Hexo的建站之旅"></a>Hexo的建站之旅</h2><p>一直想搭建一个属于自己的博客，从3个月前用H5页面打造的简历，到今天的Hexo最初的想法是用前端技术从前台一直搭到后台，无奈时间来不及。目前正在写一个自己的库和翻看jquery的源码，同时也确实意识到不一定所有的东西都要自己造轮子，所以选择了Hexo来快速建站。提前开始自己的书写之旅。</p>
<h3 id="关于代码"><a href="#关于代码" class="headerlink" title="关于代码"></a>关于代码</h3><p>Hexo的搭建十分简单，但是现在的版本也十分简陋，还没有进行排版和打造留言模块，接下来会添加上来。包括标签，搜索栏等等。先尝试着用MrakDown的语法发了这篇博客，也算是插了个旗帜。所以，这就是第一篇hello world了。</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://github.com/remarkableRide/io/2017/05/01/hello-world/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="remarkableRide">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="RemarkableRide">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2017/05/01/hello-world/" itemprop="url">
                  Hello World
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-05-01T12:52:49+08:00">
                2017-05-01
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计</span>
                
                <span title="字数统计">
                  78
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长</span>
                
                <span title="阅读时长">
                  1
                </span>
              
            </div>
          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Welcome to <a href="https://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="external">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="external">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo new <span class="string">"My New Post"</span></div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="external">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo server</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="external">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo generate</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
  </section>

  


          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="remarkableRide" />
          <p class="site-author-name" itemprop="name">remarkableRide</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/remarkableRide" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        
          
             <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=35032655&auto=0&height=66"></iframe>
         
        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">remarkableRide</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  






  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>





  

  

  

  

</body>
</html>
